package view;

import entity.User;
import service.impl.UserServiceImpl;
import util.InputUtil;

public class LoginView {
    private final UserServiceImpl userService = new UserServiceImpl();

    public void start() {
        while (true) {
            System.out.print("用户名：");
            String username = InputUtil.nextLine();
            System.out.print("密码：");
            String password = InputUtil.nextLine();

            User user = userService.login(username, password);
            if (user == null) {
                System.out.println("登录失败！");
            } else {
                System.out.println("欢迎，" + user.getType());
                switch (user.getType()) {
                    case "管理员":
                        new AdminView(userService).start();
                        break;
                    case "经理":
                        new ManagerView().start();
                        break;
                    case "前台":
                        new CounterView().start();
                        break;
                }
            }
        }
    }
}